﻿/**
 @author Eric AMBROSI
 @alias ricko || rickota || ricota
 @classDescription allow to tween object in Silverlight 2
 @version 2.1.2 stable version
*/

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Tweened
{   
    /// <summary>
    /// 	This is where are all available easing equations. Easing Equations (c) 2003 Robert Penner, all rights reserved.
    ///     NB: I have of course not created the following equations, as a flasher I am a fan of Robert Penner therefore I preferred integrated endorse.
    /// </summary>
    /// <remarks>
    ///     	Animations for opacity it is better to choose Equation.Linear 
    ///     	TweenObject witch affects a color property only have Linears Equations
    /// </remarks>
    public static class TweenedEquations
    {
        /*
        Easing Equations (c) 2003 Robert Penner, all rights reserved.
        NB : je n'ai bien entendu pas créé les équation suivantes, en tant que flasheur je suis fan de Robert donc j'ai préféré intégré le siennes
        */
        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseOutElastic(double t, double b, double c, double d)
        {
            if ((t /= d) == 1) return b + c;
            double p = d * .3;
            double s = p / 4;
            return (c * Math.Pow(2, -10 * t) * Math.Sin((t * d - s) * (2 * Math.PI) / p) + c + b);
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseInElastic(double t, double b, double c, double d)
        {
            if ((t /= d) == 1) return b + c;
            double p = d * .3;
            double s = p / 4;
            return -(c * Math.Pow(2, 10 * (t -= 1)) * Math.Sin((t * d - s) * (2 * Math.PI) / p)) + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseInOutElastic(double t, double b, double c, double d)
        {
            if ((t /= d / 2) == 2) return b + c;
            double p = d * (.3 * 1.5);
            double s = p / 4;
            if (t < 1) return -.5 * (c * Math.Pow(2, 10 * (t -= 1)) * Math.Sin((t * d - s) * (2 * Math.PI) / p)) + b;
            return c * Math.Pow(2, -10 * (t -= 1)) * Math.Sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseOutBounce(double t, double b, double c, double d)
        {
            if ((t /= d) < (1 / 2.75)) return c * (7.5625 * t * t) + b;
            else if (t < (2 / 2.75)) return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
            else if (t < (2.5 / 2.75)) return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
            else return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseInBounce(double t, double b, double c, double d)
        {
            return c - EaseOutBounce (d-t, 0, c, d) + b;
        }
 
        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseInOutBounce(double t, double b, double c, double d)
        {
            if (t < d / 2) return EaseInBounce(t * 2, 0, c, d) * .5 + b;
            else return EaseOutBounce(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseOutExpo(double t, double b, double c, double d)
        {
            return (t == d) ? b + c : c * (-Math.Pow(2, -10 * t / d) + 1) + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseInExpo(double t, double b, double c, double d)
        {
            return (t == 0) ? b : c * Math.Pow(2, 10 * (t / d - 1)) + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseInOutExpo(double t, double b, double c, double d)
        {
            if (t == 0) return b;
            if (t == d) return b + c;
            if ((t /= d / 2) < 1) return c / 2 * Math.Pow(2, 10 * (t - 1)) + b;
            return c / 2 * (-Math.Pow(2, -10 * --t) + 2) + b;
        }
        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseOutQuad(double t, double b, double c, double d)
        {
            return -c * (t /= d) * (t - 2) + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseInQuad(double t, double b, double c, double d)
        {
            return c * (t /= d) * t + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseInOutQuad(double t, double b, double c, double d)
        {
            if ((t /= d / 2) < 1) return c / 2 * t * t + b;
            return -c / 2 * ((--t) * (t - 2) - 1) + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseOutSine(double t, double b, double c, double d)
        {
            return c * Math.Sin(t / d * (Math.PI / 2)) + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseInSine(double t, double b, double c, double d)
        {
            return -c * Math.Cos(t / d * (Math.PI / 2)) + c + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseInOutSine(double t, double b, double c, double d)
        {
            if ((t /= d / 2) < 1) return c / 2 * (Math.Sin(Math.PI * t / 2)) + b;
            return -c / 2 * (Math.Cos(Math.PI * --t / 2) - 2) + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseOutCirc(double t, double b, double c, double d)
        {
            return c * Math.Sqrt(1 - (t = t / d - 1) * t) + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseInCirc(double t, double b, double c, double d)
        {
            return -c * (Math.Sqrt(1 - (t /= d) * t) - 1) + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseInOutCirc(double t, double b, double c, double d)
        {
            if ((t /= d / 2) < 1) return -c / 2 * (Math.Sqrt(1 - t * t) - 1) + b;
            return c / 2 * (Math.Sqrt(1 - (t -= 2) * t) + 1) + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseOutCubic(double t, double b, double c, double d)
        {
            return c * ((t = t / d - 1) * t * t + 1) + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseInCubic(double t, double b, double c, double d)
        {
            return c * (t /= d) * t * t + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseInOutCubic(double t, double b, double c, double d)
        {
            if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
            return c / 2 * ((t -= 2) * t * t + 2) + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseOutQuint(double t, double b, double c, double d)
        {
            return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseInQuint(double t, double b, double c, double d)
        {
            return c * (t /= d) * t * t * t * t + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseInOutQuint(double t, double b, double c, double d)
        {
            if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b;
            return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseOutBack(double t, double b, double c, double d)
        {
            return c * ((t = t / d - 1) * t * ((1.70158 + 1) * t + 1.70158) + 1) + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseInBack(double t, double b, double c, double d)
        {
            return c * (t /= d) * t * ((1.70158 + 1) * t - 1.70158) + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseInOutBack(double t, double b, double c, double d)
        {
            double s = 1.70158;
            if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
            return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseOutQuart(double t, double b, double c, double d)
        {
            return -c * ((t = t / d - 1) * t * t * t - 1) + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseInQuart(double t, double b, double c, double d)
        {
            return c * (t /= d) * t * t * t + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double EaseInOutQuart(double t, double b, double c, double d)
        {
            if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b;
            return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
        }

        /// <summary>
        /// see http://library.tweened.org for more informations 
        /// </summary>
        /// <param name="t">CurrentTime</param>
        /// <param name="b">StartValue</param>
        /// <param name="c">ChangeValue</param>
        /// <param name="d">Duration</param>
        /// <returns>double result Value</returns>
        public static double Linear(double t, double b, double c, double d)
        {
            return c * t / d + b;
        }

        public static double easeOutQuad(double t, double b, double c, double d)
        {
            return -c * (t /= d) * (t - 2) + b;
        }

        public static double easeInQuad(double t, double b, double c, double d)
        {
            return c * (t /= d) * t + b;
        }

        public static double easeInOutQuad(double t, double b, double c, double d)
        {
            if ((t /= d / 2) < 1) return c / 2 * t * t + b;
            return -c / 2 * ((--t) * (t - 2) - 1) + b;
        }

        public static double easeOutSine(double t, double b, double c, double d)
        {
            return c * Math.Sin(t / d * (Math.PI / 2)) + b;
        }

        public static double easeInSine(double t, double b, double c, double d)
        {
            return -c * Math.Cos(t / d * (Math.PI / 2)) + c + b;
        }

        public static double easeInOutSine(double t, double b, double c, double d)
        {
            if ((t /= d / 2) < 1) return c / 2 * (Math.Sin(Math.PI * t / 2)) + b;
            return -c / 2 * (Math.Cos(Math.PI * --t / 2) - 2) + b;
        }
        public static double easeOutQuint(double t, double b, double c, double d)
        {
            return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
        }

        public static double easeInQuint(double t, double b, double c, double d)
        {
            return c * (t /= d) * t * t * t * t + b;
        }

        public static double easeInOutQuint(double t, double b, double c, double d)
        {
            if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b;
            return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
        }

        public static double easeOutQuart(double t, double b, double c, double d)
        {
            return -c * ((t = t / d - 1) * t * t * t - 1) + b;
        }

        public static double easeInQuart(double t, double b, double c, double d)
        {
            return c * (t /= d) * t * t * t + b;
        }

        public static double easeInOutQuart(double t, double b, double c, double d)
        {
            if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b;
            return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
        }
    }

}
